﻿using APP.HELPER.Data.Helper;
using APP.HELPER.Utils.CustomizeToolbox;
using DevExpress.XtraEditors;
using System;
using System.Data;
using System.Data.SqlClient;
using ComboBox = System.Windows.Forms.ComboBox;

namespace Security.ERP
{
    public class SYS_GROUP
    {
        private string m_Group_ID;
        private string m_Group_Name;
        private string m_Group_NameEn;
        private string m_Description;
        private bool m_Active;
        public string Group_ID
        {
            get
            {
                return this.m_Group_ID;
            }
            set
            {
                this.m_Group_ID = value;
            }
        }
        public string Group_Name
        {
            get
            {
                return this.m_Group_Name;
            }
            set
            {
                this.m_Group_Name = value;
            }
        }
        public string Group_NameEn
        {
            get
            {
                return this.m_Group_NameEn;
            }
            set
            {
                this.m_Group_NameEn = value;
            }
        }
        public string Description
        {
            get
            {
                return this.m_Description;
            }
            set
            {
                this.m_Description = value;
            }
        }
        public bool Active
        {
            get
            {
                return this.m_Active;
            }
            set
            {
                this.m_Active = value;
            }
        }
        public string ProductName
        {
            get
            {
                return "Class SYS_GROUP";
            }
        }
        public string ProductVersion
        {
            get
            {
                return "1.0.0.0";
            }
        }
        public SYS_GROUP()
        {
            this.m_Group_ID = "";
            this.m_Group_Name = "";
            this.m_Group_NameEn = "";
            this.m_Description = "";
            this.m_Active = true;
        }
        public SYS_GROUP(string Group_ID, string Group_Name, string Group_NameEn, string Description, bool Active)
        {
            this.m_Group_ID = Group_ID;
            this.m_Group_Name = Group_Name;
            this.m_Group_NameEn = Group_NameEn;
            this.m_Description = Description;
            this.m_Active = Active;
        }
        public string NewID()
        {
            return SqlHelper.GenCode("SYS_GROUP", "Group_ID", "VT");
        }
        public bool Exist(string Group_ID)
        {
            bool result = false;
            string[] myParams = new string[]
			{
				"@Group_ID"
			};
            object[] myValues = new object[]
			{
				Group_ID
			};
            SqlHelper sqlHelper = new SqlHelper();
            SqlDataReader sqlDataReader = sqlHelper.ExecuteReader("SYS_GROUP_Get", myParams, myValues);
            if (sqlDataReader != null)
            {
                result = sqlDataReader.HasRows;
                sqlDataReader.Close();
                sqlHelper.Close();
            }
            return result;
        }
        public string Get(string Group_ID)
        {
            string result = "";
            string[] myParams = new string[]
			{
				"@Group_ID"
			};
            object[] myValues = new object[]
			{
				Group_ID
			};
            SqlHelper sqlHelper = new SqlHelper();
            SqlDataReader sqlDataReader = sqlHelper.ExecuteReader("SYS_GROUP_Get", myParams, myValues);
            if (sqlDataReader != null)
            {
                while (sqlDataReader.Read())
                {
                    this.m_Group_ID = Convert.ToString(sqlDataReader["Group_ID"]);
                    this.m_Group_Name = Convert.ToString(sqlDataReader["Group_Name"]);
                    this.m_Group_NameEn = Convert.ToString(sqlDataReader["Group_NameEn"]);
                    this.m_Description = Convert.ToString(sqlDataReader["Description"]);
                    this.m_Active = Convert.ToBoolean(sqlDataReader["Active"]);
                    result = "OK";
                }
                sqlDataReader.Close();
                sqlHelper.Close();
            }
            return result;
        }
        public string Get(SqlConnection myConnection, string Group_ID)
        {
            string result = "";
            string[] myParams = new string[]
			{
				"@Group_ID"
			};
            object[] myValues = new object[]
			{
				Group_ID
			};
            SqlHelper sqlHelper = new SqlHelper();
            SqlDataReader sqlDataReader = sqlHelper.ExecuteReader(myConnection, "SYS_GROUP_Get", myParams, myValues);
            if (sqlDataReader != null)
            {
                while (sqlDataReader.Read())
                {
                    this.m_Group_ID = Convert.ToString(sqlDataReader["Group_ID"]);
                    this.m_Group_Name = Convert.ToString(sqlDataReader["Group_Name"]);
                    this.m_Group_NameEn = Convert.ToString(sqlDataReader["Group_NameEn"]);
                    this.m_Description = Convert.ToString(sqlDataReader["Description"]);
                    this.m_Active = Convert.ToBoolean(sqlDataReader["Active"]);
                    result = "OK";
                }
                sqlDataReader.Close();
                sqlHelper.Close();
            }
            return result;
        }
        public string Get(SqlTransaction myTransaction, string Group_ID)
        {
            string result = "";
            string[] myParams = new string[]
			{
				"@Group_ID"
			};
            object[] myValues = new object[]
			{
				Group_ID
			};
            SqlHelper sqlHelper = new SqlHelper();
            SqlDataReader sqlDataReader = sqlHelper.ExecuteReader(myTransaction, "SYS_GROUP_Get", myParams, myValues);
            if (sqlDataReader != null)
            {
                while (sqlDataReader.Read())
                {
                    this.m_Group_ID = Convert.ToString(sqlDataReader["Group_ID"]);
                    this.m_Group_Name = Convert.ToString(sqlDataReader["Group_Name"]);
                    this.m_Group_NameEn = Convert.ToString(sqlDataReader["Group_NameEn"]);
                    this.m_Description = Convert.ToString(sqlDataReader["Description"]);
                    this.m_Active = Convert.ToBoolean(sqlDataReader["Active"]);
                    result = "OK";
                }
                sqlDataReader.Close();
                sqlHelper.Close();
            }
            return result;
        }
        public string Insert()
        {
            string[] myParams = new string[]
			{
				"@Group_ID",
				"@Group_Name",
				"@Group_NameEn",
				"@Description",
				"@Active"
			};
            object[] myValues = new object[]
			{
				this.m_Group_ID,
				this.m_Group_Name,
				this.m_Group_NameEn,
				this.m_Description,
				this.m_Active
			};
            SqlHelper sqlHelper = new SqlHelper();
            return sqlHelper.ExecuteNonQuery("SYS_GROUP_Insert", myParams, myValues);
        }
        public string Insert(SqlTransaction myTransaction)
        {
            string[] myParams = new string[]
			{
				"@Group_ID",
				"@Group_Name",
				"@Group_NameEn",
				"@Description",
				"@Active"
			};
            object[] myValues = new object[]
			{
				this.m_Group_ID,
				this.m_Group_Name,
				this.m_Group_NameEn,
				this.m_Description,
				this.m_Active
			};
            SqlHelper sqlHelper = new SqlHelper();
            return sqlHelper.ExecuteNonQuery(myTransaction, "SYS_GROUP_Insert", myParams, myValues);
        }
        public string Insert(string Group_ID, string Group_Name, string Group_NameEn, string Description, bool Active)
        {
            string[] myParams = new string[]
			{
				"@Group_ID",
				"@Group_Name",
				"@Group_NameEn",
				"@Description",
				"@Active"
			};
            object[] myValues = new object[]
			{
				Group_ID,
				Group_Name,
				Group_NameEn,
				Description,
				Active
			};
            SqlHelper sqlHelper = new SqlHelper();
            return sqlHelper.ExecuteNonQuery("SYS_GROUP_Insert", myParams, myValues);
        }
        public string Insert(SqlConnection myConnection, string Group_ID, string Group_Name, string Group_NameEn, string Description, bool Active)
        {
            string[] myParams = new string[]
			{
				"@Group_ID",
				"@Group_Name",
				"@Group_NameEn",
				"@Description",
				"@Active"
			};
            object[] myValues = new object[]
			{
				Group_ID,
				Group_Name,
				Group_NameEn,
				Description,
				Active
			};
            SqlHelper sqlHelper = new SqlHelper();
            return sqlHelper.ExecuteNonQuery(myConnection, "SYS_GROUP_Insert", myParams, myValues);
        }
        public string Insert(SqlTransaction myTransaction, string Group_ID, string Group_Name, string Group_NameEn, string Description, bool Active)
        {
            string[] myParams = new string[]
			{
				"@Group_ID",
				"@Group_Name",
				"@Group_NameEn",
				"@Description",
				"@Active"
			};
            object[] myValues = new object[]
			{
				Group_ID,
				Group_Name,
				Group_NameEn,
				Description,
				Active
			};
            SqlHelper sqlHelper = new SqlHelper();
            return sqlHelper.ExecuteNonQuery(myTransaction, "SYS_GROUP_Insert", myParams, myValues);
        }
        public string Update()
        {
            string[] myParams = new string[]
			{
				"@Group_ID",
				"@Group_Name",
				"@Group_NameEn",
				"@Description",
				"@Active"
			};
            object[] myValues = new object[]
			{
				this.m_Group_ID,
				this.m_Group_Name,
				this.m_Group_NameEn,
				this.m_Description,
				this.m_Active
			};
            SqlHelper sqlHelper = new SqlHelper();
            return sqlHelper.ExecuteNonQuery("SYS_GROUP_Update", myParams, myValues);
        }
        public string Update(string Group_ID, string Group_Name, string Group_NameEn, string Description, bool Active)
        {
            string[] myParams = new string[]
			{
				"@Group_ID",
				"@Group_Name",
				"@Group_NameEn",
				"@Description",
				"@Active"
			};
            object[] myValues = new object[]
			{
				Group_ID,
				Group_Name,
				Group_NameEn,
				Description,
				Active
			};
            SqlHelper sqlHelper = new SqlHelper();
            return sqlHelper.ExecuteNonQuery("SYS_GROUP_Update", myParams, myValues);
        }
        public string Update(SqlConnection myConnection, string Group_ID, string Group_Name, string Group_NameEn, string Description, bool Active)
        {
            string[] myParams = new string[]
			{
				"@Group_ID",
				"@Group_Name",
				"@Group_NameEn",
				"@Description",
				"@Active"
			};
            object[] myValues = new object[]
			{
				Group_ID,
				Group_Name,
				Group_NameEn,
				Description,
				Active
			};
            SqlHelper sqlHelper = new SqlHelper();
            return sqlHelper.ExecuteNonQuery(myConnection, "SYS_GROUP_Update", myParams, myValues);
        }
        public string Update(SqlTransaction myTransaction, string Group_ID, string Group_Name, string Group_NameEn, string Description, bool Active)
        {
            string[] myParams = new string[]
			{
				"@Group_ID",
				"@Group_Name",
				"@Group_NameEn",
				"@Description",
				"@Active"
			};
            object[] myValues = new object[]
			{
				Group_ID,
				Group_Name,
				Group_NameEn,
				Description,
				Active
			};
            SqlHelper sqlHelper = new SqlHelper();
            return sqlHelper.ExecuteNonQuery(myTransaction, "SYS_GROUP_Update", myParams, myValues);
        }
        public string Delete()
        {
            string[] myParams = new string[]
			{
				"@Group_ID"
			};
            object[] myValues = new object[]
			{
				this.m_Group_ID
			};
            SqlHelper sqlHelper = new SqlHelper();
            return sqlHelper.ExecuteNonQuery("SYS_GROUP_Delete", myParams, myValues);
        }
        public string Delete(string Group_ID)
        {
            string[] myParams = new string[]
			{
				"@Group_ID"
			};
            object[] myValues = new object[]
			{
				Group_ID
			};
            SqlHelper sqlHelper = new SqlHelper();
            return sqlHelper.ExecuteNonQuery("SYS_GROUP_Delete", myParams, myValues);
        }
        public string Delete(SqlConnection myConnection, string Group_ID)
        {
            string[] myParams = new string[]
			{
				"@Group_ID"
			};
            object[] myValues = new object[]
			{
				Group_ID
			};
            SqlHelper sqlHelper = new SqlHelper();
            return sqlHelper.ExecuteNonQuery(myConnection, "SYS_GROUP_Delete", myParams, myValues);
        }
        public string Delete(SqlTransaction myTransaction, string Group_ID)
        {
            string[] myParams = new string[]
			{
				"@Group_ID"
			};
            object[] myValues = new object[]
			{
				Group_ID
			};
            SqlHelper sqlHelper = new SqlHelper();
            return sqlHelper.ExecuteNonQuery(myTransaction, "SYS_GROUP_Delete", myParams, myValues);
        }
        public DataTable GetList()
        {
            SqlHelper sqlHelper = new SqlHelper();
            return sqlHelper.ExecuteDataTable("SYS_GROUP_GetList");
        }
        public DataTable Get_List(string Group_ID)
        {
            string[] myParams = new string[]
			{
				"@Group_ID"
			};
            object[] myValues = new object[]
			{
				Group_ID
			};
            SqlHelper sqlHelper = new SqlHelper();
            return sqlHelper.ExecuteDataTable("SYS_GROUP_Get", myParams, myValues);
        }
        public void AddCombo(ComboBox combo)
        {
            GridCalendarControlLib.TableToComboBox(combo, this.GetList(), "SYS_GROUPName", "SYS_GROUPID");
        }
        public void AddComboEdit(ComboBoxEdit combo)
        {
            DataTable dataTable = new DataTable();
            dataTable = this.GetList();
            foreach (DataRow dataRow in dataTable.Rows)
            {
                combo.Properties.Items.Add(dataRow["Group_Name"]);
            }
        }
        public void AddGridLookupEdit(GridLookUpEdit glkEdit)
        {
            DataTable dataSource = new DataTable();
            dataSource = this.GetList();
            glkEdit.Properties.DataSource = dataSource;
            glkEdit.Properties.DisplayMember = "Group_Name";
            glkEdit.Properties.ValueMember = "Group_ID";
        }
        public void AddComboAll(ComboBox combo)
        {
            DataTable dataTable = new DataTable();
            dataTable = this.GetList();
            DataRow dataRow = dataTable.NewRow();
            dataRow["SYS_GROUPID"] = "All";
            dataRow["SYS_GROUPName"] = "Tất cả";
            dataTable.Rows.InsertAt(dataRow, 0);
            GridCalendarControlLib.TableToComboBox(combo, dataTable, "SYS_GROUPName", "SYS_GROUPID");
        }
    }
}